package com.winchain.chainbill.bill.base.service.impl;

import com.shell.bee.acct.account.util.VirtualAcctUtil;
import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.winchain.chainbill.ChainBillUtil;
import com.winchain.chainbill.bill.base.dao.CbRecDao;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.service.CbRecService;
import com.winchain.chainbill.bill.biz.query.vo.CbRecVo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("cbRecService")
public class CbRecServiceImpl extends PersistentServiceImpl<CbRec> implements CbRecService {
	@Autowired
	private CbRecDao cbRecDao;

	public int updateBillOptimistically(CbRec bill) {
		return this.cbRecDao.updateBillOptimistically(bill);
	}

	public List<CbRecVo> selectBillForPrepayment(String workDate, String billState) {
		return this.cbRecDao.selectBillForPrepayment(workDate, billState);
	}

	public List<CbRecVo> selectBillForTimeOut(String theDayBefore, String sevenDaysAgo, String threeDaysLater,
			String oneDayAfter) {
		return this.cbRecDao.selectBillForTimeOut(theDayBefore, sevenDaysAgo, threeDaysLater, oneDayAfter);
	}

	public List<CbRecVo> selectBillsByExpireDate(String expireDate, List<String> stateList) {
		String acctType = "0";
		if ((ChainBillUtil.onlinePay()) && (VirtualAcctUtil.onVirtual())) {
			acctType = "1";
		}
		return this.cbRecDao.selectBillsByExpireDate(expireDate, acctType, stateList);
	}

	public List<CbRec> selectExpSndBills(String expDate, String grpId, List<String> notInStates) {
		return this.cbRecDao.selectExpSndBills(expDate, grpId, notInStates);
	}

	public List<CbRec> selectExpDlyBills(String expDate, String grpId, List<String> notInStates) {
		return this.cbRecDao.selectExpDlyBills(expDate, grpId, notInStates);
	}

	public List<CbRecVo> selectBillForPrefinancing(String dctDate) {
		return this.cbRecDao.selectBillForPrefinancing(dctDate);
	}

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public CbRec selectByKeyWithNewTx(String billId) {
		return (CbRec) selectByKey(billId);
	}

	public List<CbRec> selectExpChdBills(String expDate, String billId, List<String> notInStates) {
		return this.cbRecDao.selectExpChdBills(expDate, billId, notInStates);
	}

	public CbRec selectLeafBills(String rootId, String billId) {
		return this.cbRecDao.selectLeafBills(rootId, billId);
	}
}
